package org.meproj.aodv.bl;

import java.util.ArrayList;
import java.util.List;

import org.meproj.communication.bean.Roles;
import org.meproj.communication.bean.Signal;

public class AvoidWormhole {

	// TODO: Try to get a more realistic value.
	private static int MAX_OCCURANCE_THREASHOLD = 5; 
	
	private class SessionData {
	
	}
	
	private Roles currentRole = Roles.NULL_ADAPTER;
	private String includeExtraMessage = null;
	
	public void businessLogicForReceiveSignal(Signal signal) {
		
		if(currentRole == Roles.NULL_ADAPTER) {
			
			currentRole.setDegree(signal.getCurrentRole().getDegree() - 1);
			signal.setCurrentRole(currentRole);
		}
		
		List<List<String>> allRoutes = getAllRoutingTableFromMe(signal.getToNode());
		String mNode = getMNodeWithMaxOccurance(allRoutes);
		
		if(mNode != null || mNode.trim().length() > 0 ) {
			currentRole = Roles.EARLY_ADAPTER;
		}
	}
	
	public void businessLogicForSendSignal(Signal signal) {
		
		signal.setCurrentRole(currentRole);
		
		if(includeExtraMessage != null) {
			signal.setApplicationSpecificData(includeExtraMessage);
		}
		
	}
	
	public List<List<String>> getAllRoutingTableFromMe(String destination) {
		
		List<List<String>> route = new ArrayList<List<String>>();
		
		return route;
	}
	
	public String getMNodeWithMaxOccurance(List<List<String>> allRoutes) {
		
		String mNode = null;
		
		return mNode;
	}
}
